<template>
  <div class="inside-page">
    <div class="company-wrap">
      <div class="company-wrap-container">
        <div class="wrap-left">
          <img :src="info.logo" />
        </div>
        <div class="wrap-right">
          <p class="company-name">{{ info.cname }}</p>
          <div class="pro">
            <span>{{ info.industry_data }}</span>
            <span>{{ info.attr_data }}</span>
            <span>{{ info.size_data }}</span>
          </div>
          <div class="text">
            <el-button type="primary" v-permission="['personal']" @click="connect">联系企业</el-button>
            <span
              class="tag"
              v-for="(v, i) in info.welfare"
              :key="'welfare_' + i"
              >{{ v }}</span
            >

          </div>
        </div>
        <div class="company-data">
          <div class="data">
            <p class="num">{{ info.count_job }}</p>
            <p class="text">在招职位</p>
          </div>
          <div class="data">
            <p class="num">{{ info.hot }}</p>
            <p class="text">企业热度</p>
          </div>

        </div>
      </div>
    </div>
    <div class="company-detail content">
      <p class="detail-title">企业简介</p>
      <div class="intro-text">
        <p class="con" v-html="intro"></p>
        <p v-if="showToggle" class="toggle-btn" @click="toggleText">
          {{ toggleActive ? '收起' : '展开' }}
        </p>
      </div>
      <p class="detail-title">在招职位</p>
      <div class="pos-filter">
        <p>职位筛选：</p>
        <client-only>
          <el-select
            v-model="cityid"
            clearable
            @change="fetchData"
            placeholder="选择工作地点"
          >
            <el-option
              v-for="item in search.city"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </client-only>
        <client-only>
          <el-select
            v-model="posttypeid"
            clearable
            @change="fetchData"
            placeholder="选择职能"
          >
            <el-option
              v-for="item in search.postType"
              :key="item.id"
              :label="item.tagname"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </client-only>
      </div>
      <div class="job-list">
        <div
          class="job-item clearfix"
          v-for="j in jobList"
          :key="j.id"
          @click="jumpToJob(j.id)"
        >
          <div class="job-pos">
            <div class="text">
              <span class="job-name">{{ j.name }}</span>
              <span class="money" v-if="j.payid"
                >{{ j.payid }}-{{ j.pay_end }}k</span
              >
            </div>
            <div class="wrap">
              <p>
                <i class="iconfont icon-map"></i><span>{{ j.city_name }}</span>
              </p>
              <p>
                <i class="iconfont icon-edit"></i
                ><span>{{ j.is_all === 0 ? '实习' : '全职' }}</span>
              </p>
              <p>
                <i class="iconfont icon-hat"></i><span>{{ j.eid }}</span>
              </p>
              <p>
                <i class="iconfont icon-time"></i
                ><span>{{ j.end_time_cn }}</span>
              </p>
            </div>
          </div>
          <div class="job-company">
            <p class="name">{{ info.cname }}</p>
            <p class="type">{{ info.industry_data }}</p>
          </div>
          <div
            class="job-logo"
            :style="{
              background:
                'url(' + info.logo + ') center center / cover no-repeat',
            }"
          ></div>
        </div>
      </div>
      <client-only>
        <el-pagination
          hide-on-single-page
          background
          prev-text="上一页"
          next-text="下一页"
          layout="prev, pager, next"
          :current-page="pageNo"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
        />
      </client-only>
    </div>
  </div>
</template>

<script>
import { companyDetail } from '@/api/company';
import {addChat, addChat1} from '@/api/job';
export default {
  asyncData ({ query, error }) {
  },
  components: {},
  data () {
    return {
      authUser: null,
      id: '',
      info: {
      },
      showToggle: false,
      intro: '',
      toggleActive: false,
      jobList: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      search: {
        city: [],
        postType: [],
      },
      cityid: '',
      posttypeid: '',
    }
  },
  head () {
    return {
      titleTemplate: (titleChunk) => {
        return `${titleChunk} - 大学生找工作、找实习`;
      }
    }
  },
  created () {
    this.authUser = this.$store.state.user.authUser;
    this.id = this.$route.query.id;
    this.fetchData();
  },
  mounted () {
  },
  watch: {

  },
  computed: {

  },
  methods: {
    connect () {
      addChat1({
        cid: this.id
      }).then(res => {
        if (res.code === 200) {
          this.$message.success('添加联系人成功，可进入交流平台进行交流');
        } else {
          this.$message.error(res.msg);
        }
      }).catch(err => {
        console.error(err)
        this.$message.error(err);
      })
    },
    fetchData () {
      companyDetail({
        id: this.id,
        city_id: this.cityid,
        f_id: this.posttypeid,
      }).then(res => {
        if (res.code === 200) {
          res.data.company.description && (res.data.company.description = this.toCheck(res.data.company.description));
          this.info = res.data.company || {};
          this.jobList = res.data.job || [];
          this.search = res.data.searchDate;
          this.checkIntro();
        } else {
          this.$message.error(res.msg || '网络错误！')
        }
      }).catch(err => {
        console.error(err);
        this.$message.error(err || '网络错误！')
      })
    },
    checkIntro () { // 检查公司简介
      const originIntro = this.info.description || '';
      originIntro.length >= 150
        ? (this.intro = originIntro.slice(0, 150) + '...') && (this.showToggle = true)
        : this.intro = originIntro
    },
    toggleText () {
      this.toggleActive = !this.toggleActive;
      this.toggleActive ? (this.intro = this.info.description) : (this.intro = this.info.description.slice(0, 150) + '...');
    },
    toCheck (text) {
      return text.replace(/\n/g, '<br/>');
    },
    handleCurrentChange (val) {
      this.pageNo = val;
      this.getPageArticle();
    },
    jumpToJob (id) {
      this.$router.push({
        path: '/job/detail',
        query: { id }
      })
    },
    jumpTo () {

    },
  },
}
</script>

<style lang="scss" scoped>
.inside-page {
  width: 100%;
  position: relative;
  .company-wrap {
    width: 100%;
    height: 220px;
    padding-top: 40px;
    position: relative;
    background: url(../../static/building.png) center / cover no-repeat;
    .company-wrap-container {
      width: $base-width;
      margin: 0 auto;
      position: relative;
      .wrap-left {
        float: left;
        margin-top: 5px;
        height: 120px;
        width: 120px;
        overflow: hidden;
        background: #fff;
        border-radius: 8px;
        text-align: center;
        img {
          height: 120px;
        }
      }
      .wrap-right {
        float: left;
        margin-left: 20px;
        .company-name {
          font-size: 36px;
          color: #fff;
        }
        .pro {
          margin: 10px 0 20px 0;
          span {
            color: #fff;
          }
        }
        .text {
          .tag {
            font-size: 12px;
            color: $base-color;
            padding: 4px 8px;
            border: 1px solid $base-color;
            border-radius: 4px;
            margin-right: 10px;
          }
        }
      }
      .company-data {
        position: absolute;
        right: 0;
        top: 30px;
        .data {
          float: left;
          text-align: center;
          padding-left: 30px;
          &:first-child {
            padding-left: 0;
          }
          .num {
            font-size: 36px;
            color: #fff;
          }
          .text {
            font-size: 14px;
            color: $base-color;
          }
        }
      }
    }
  }
  .company-detail {
    position: relative;
    .intro-text {
      position: relative;
      padding: 20px 0;
      border-bottom: 1px solid #ebebeb;
      p {
        font-size: 16px;
        line-height: 32px;
      }
      .con {
        color: #666;
      }
      .toggle-btn {
        position: absolute;
        right: 0;
        bottom: 20px;
        color: $base-color;
        &:hover {
          cursor: pointer;
          color: $base-color-hover;
        }
      }
    }
    .pos-filter {
      height: 50px;
      line-height: 40px;
      padding-top: 10px;
      p {
        float: left;
      }
      ::v-deep .el-input__inner {
        height: 30px;
        line-height: 30px;
      }
    }
  }

  .job-list {
    margin: 20px auto;
    .job-item {
      height: 120px;
      width: 100%;
      border: 1px solid #ebebeb;
      background: #fff;
      margin-bottom: 10px;
      padding: 0 40px 0 40px;
      cursor: pointer;
      &:hover {
        background: #f6f7f8;
      }
      & > div {
        float: left;
      }
      .job-pos {
        width: 700px;
        font-size: 18px;
        margin-top: 30px;
        .job-name {
          color: #242924;
          margin-right: 40px;
        }
        .money {
          color: $base-color-important;
          white-space: nowrap;
        }
        .wrap {
          margin-top: 10px;
          p {
            margin-right: 30px;
            color: #999;
            line-height: 20px;
            font-size: 14px;
            display: inline-block;
          }
          i {
            vertical-align: middle;
            color: #999;
            margin-right: 5px;
          }
          span {
            vertical-align: middle;
            color: #999;
          }
        }
      }
      .job-company {
        margin-top: 30px;
        width: 340px;
        .name {
          color: #24292f;
          margin-top: 10px;
        }
        .type {
          color: #999;
          font-size: 12px;
          margin-top: 5px;
        }
      }
      .job-logo {
        margin-top: 24px;
        width: 74px;
        height: 74px;
        overflow: hidden;
      }
    }
  }
}
</style>
